﻿/*
 * Copyright 2010 Pieter De Rycke
 *
 * This file is part of Frozen Bubble XNA.
 *
 * Frozen Bubble XNA is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2, as published by the Free Software Foundation.
 *
 * Frozen Bubble XNA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Frozen Bubble XNA. If not, see 
 * <http://www.gnu.org/licenses/>.
 *
 * Artwork:
 *    Alexis Younes <73lab at free.fr>
 *      (everything but the bubbles)
 *    Amaury Amblard-Ladurantie <amaury at linuxfr.org>
 *      (the bubbles)
 *
 * Soundtrack:
 *    Matthias Le Bidan <matthias.le_bidan at caramail.com>
 *      (the three musics and all the sound effects)
 *
 * Design & Programming:
 *    Guillaume Cottenceau <guillaume.cottenceau at free.fr>
 *      (design and manage the project, whole Perl sourcecode)
 *
 * XNA and Windows Phone 7 port:
 *    Pieter De Rycke
 *
 * Websites:
 *    http://www.frozen-bubble.org/
 *    http://pieterderycke.wordpress.com/
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace FrozenBubble
{
    /// <summary>
    /// An input controller for handling keyboard input.
    /// </summary>
    public class KeyboardController : GameComponent, IInputController
    {
        private InputState _state;

        public KeyboardController(Game game)
            : base(game)
        { 
        }

        public override void Update(GameTime gameTime)
        {
            KeyboardState input = Keyboard.GetState();

            bool left = input.IsKeyDown(Keys.Left);
            bool right = input.IsKeyDown(Keys.Right);
            bool fire = input.IsKeyDown(Keys.Space) || input.IsKeyDown(Keys.Up);
            bool center = false;
            bool pause = input.IsKeyDown(Keys.P);
            bool end = input.IsKeyDown(Keys.Escape);

            // In the keyboard controller is any for the moment equal to the fire action
            _state = new InputState(left, right, fire, center, pause, fire, end);
        }

        public InputState State
        {
            get 
            {
                return _state;
            }
        }
    }
}
